package gen.tools.svn;

import gen.tools.Widgets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.GsonBuilder;

public class QuerySVNfileInJson extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public QuerySVNfileInJson() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		final Widgets wid = new Widgets();
		response.setCharacterEncoding( wid.UIcodeSet );
		response.setContentType("application/text");
		
		final String svnURL = request.getParameter("svnURL");
        final String svnUSR = request.getParameter("svnUSR");
        final String svnPWD = request.getParameter("svnPWD");
		
		
		String res=null;
		
		try {
			res = wid.getSVN2depFileTreeJSON(svnURL, svnUSR, svnPWD);
		} catch (Exception e) {
			wid.errLog(e);
		}
		
		response.getWriter().write( new GsonBuilder().disableHtmlEscaping().create().toJson( res ).replaceAll("'", "\"") );
	}

}
